home *** CD-ROM | disk | FTP | other *** search
File List | 1989-09-12 | 8.9 KB | 257 lines |
- ' PROGRAM: Dialog Box Tutorial
- DIM medrbtn&(3),denrbtn&(2)
- GOSUB my_menu
- GOSUB initialize
- GOSUB window_open
- GOSUB ld_resource
- ON MENU GOSUB respond_menu
- DO
- ON MENU
- LOOP
- PROCEDURE respond_menu
- ' Procedure to respond to menu items
- hold$=strip$(MENU(0))
- IF hold$="Dialog Tutorial"
- ' code to handle Desk menu item here
- txt$="Dialog Box Tutorial|By David Plotkin"
- ALERT 1,txt$,1,"OK",a%
- ENDIF
- IF hold$="Add info"
- ' code for Add info
- GOSUB show_resource
- ENDIF
- IF hold$="Quit"
- ' code for Quit
- GOSUB pgm_end
- ENDIF
- MENU OFF
- RETURN
- PROCEDURE my_menu
- ' Menu definition procedure
- MENU KILL
- RESTORE m_data
- DIM strip$(150)
- FOR i%=0 TO 150
- READ strip$(i%)
- EXIT IF strip$(i%)="***"
- NEXT i%
- strip$(i%)=""
- strip$(i%+1)=""
- m_data:
- DATA Desk,"Dialog Tutorial"
- DATA -------------------
- DATA 1,2,3,4,5,6,""
- DATA File,Add info,--------------,Quit
- DATA ***
- MENU strip$()
- RETURN
- PROCEDURE initialize
- ' initializes variables
- ' These variable statements were written out by the Resource
- ' Construction Set by toggling the box to write GFA Output under OUTPUT
- ' in the GLOBAL menu item. For this to work, you must have provided
- ' an name for each item in the dialog box while using RSC.
- LET benefits&=0 !RSC_TREE
- LET title&=1 !Dialog box title string
- LET name&=2 !Editable text field for name
- LET address&=3 !Editable text field for street address
- LET city&=4 !Editable text field for city
- LET state&=5 !Editable text field for state
- LET zip&=6 !Editable text field for zipcode
- LET box1&=7 !Box around the medical plans(groups radio buttons)
- LET box2&=12 !Box around the dental plans(groups radio buttons)
- LET mplana&=9 !Medical plan A radio button
- LET mplanb&=10 !Medical plan B radio button
- LET mplanc&=11 !Medical plan C radio button
- LET dplana&=14 !Dental plan A radio button
- LET dplanb&=15 !Dental plan B radio button
- LET depno&=17 !Title string for number of dependents
- LET depup&=18 !Button to increase number of dependents (touchexit)
- LET depdown&=16 !Button to decrease number of dependents (touchexit)
- LET depnbrsl&=26 !Button holding the number of dependents
- LET impdown&=20 !Button to decrease importance slider
- LET impup&=23 !Button to increase importance slider
- LET imparent&=21 !Box containing the importance slider
- LET impslide&=22 !The importance slider
- LET ok&=24 !OK exit button
- LET cancel&=25 !Cancel exit button
- LET mplnttle&=8 !Title string for medical plan box
- LET dplnttle&=13 !Title string for dental plan box
- ' now load the medical and dental radio button values into their arrays
- medrbtn&(1)=mplana&
- medrbtn&(2)=mplanb&
- medrbtn&(3)=mplanc&
- denrbtn&(1)=dplana&
- denrbtn&(2)=dplanb&
- RETURN
- PROCEDURE ld_resource
- ' load the resource file
- RESERVE FRE(0)-30000
- IF RSRC_LOAD("BENEFITS.RSC")=0
- ALERT 3,"Resource file not found",1," STOP ",a%
- RESERVE FRE(0)+30000
- EDIT
- ENDIF !RSRC_LOAD("BENEFITS.RSC")=0
- ~RSRC_GADDR(0,0,adr%) !get the address of the dialog box
- ' initialize the operating width of the importance slider
- width%=OB_W(adr%,imparent&)-OB_W(adr%,impslide&)
- RETURN
- PROCEDURE show_resource
- ' put the dialog box on the screen
- ~FORM_CENTER(adr%,x%,y%,w%,h%) !get the centered coordinates
- GET x%,y%,x%+w%,y%+h%,hold$ !store the screen rectangle
- ' clear the dialog box strings
- CHAR{{OB_SPEC(adr%,name&)}}=""
- CHAR{{OB_SPEC(adr%,city&)}}=""
- CHAR{{OB_SPEC(adr%,address&)}}=""
- CHAR{{OB_SPEC(adr%,state&)}}=""
- CHAR{{OB_SPEC(adr%,zip&)}}=""
- ' set the number of dependents to zero
- depnum%=0
- CHAR{OB_SPEC(adr%,depnbrsl&)}=STR$(depnum%)
- ' set the importance factor to 50
- import%=50
- CHAR{OB_SPEC(adr%,impslide&)}=STR$(import%)
- ' and the position of the slider itself to 500 (halfway)
- sliderpos%=500
- newpos%=width%/1000*sliderpos%
- OB_X(adr%,impslide&)=newpos%
- dum%=FORM_DIAL(1,0,0,0,0,x%,y%,x%+w%,y%+h%)
- ~OBJC_DRAW(adr%,0,6,x%,y%,w%,h%) ! draw the box
- REPEAT !loop til OK or CANCEL is pressed
- exit_obj%=FORM_DO(adr%,0)
- ' handle different exit objects here
- IF exit_obj%=depup& !number of dependents goes up
- INC depnum% ! increase by one
- IF depnum%>99 !make sure only two digits (otherwise,...crash!)
- depnum%=99
- ENDIF !depnum%>99
- CHAR{OB_SPEC(adr%,depnbrsl&)}=STR$(depnum%)
- ~OBJC_DRAW(adr%,depnbrsl&,6,x%,y%,w%,h%)
- ENDIF ! exit_obj%=depup&
- IF exit_obj%=depdown& !number of dependents goes down
- DEC depnum% !decrease by one
- IF depnum%<0 !hmmm, not possible
- depnum%=0 ! fix it
- ENDIF !depnum%<0
- CHAR{OB_SPEC(adr%,depnbrsl&)}=STR$(depnum%)
- ~OBJC_DRAW(adr%,depnbrsl&,6,x%,y%,w%,h%)
- ENDIF !exit_obj%=depdown&
- IF exit_obj%=impslide& !clicked on the slider itself
- ' exit dialog and allow user to drag slider to new position
- sliderpos%=GRAF_SLIDEBOX(adr%,imparent&,impslide&,0)
- newpos%=width%/1000*sliderpos%
- OB_X(adr%,impslide&)=newpos%
- ' Now set value in slider
- import%=sliderpos%/10
- CHAR{OB_SPEC(adr%,impslide&)}=STR$(import%)
- ' redraw the slider
- ~OBJC_DRAW(adr%,imparent&,3,x%,y%,w%,h%)
- ENDIF ! exit_obj%=impslide&
- IF exit_obj%=impdown& ! clicked on the down button
- SUB sliderpos%,10 ! subtract five
- IF sliderpos%<0
- sliderpos%=0
- ENDIF !sliderpos%<0
- newpos%=width%/1000*sliderpos%
- OB_X(adr%,impslide&)=newpos%
- ' Now set value in slider
- import%=sliderpos%/10
- CHAR{OB_SPEC(adr%,impslide&)}=STR$(import%)
- ' redraw the slider
- ~OBJC_DRAW(adr%,imparent&,3,x%,y%,w%,h%)
- ENDIF ! exit_obj%=impdown&
- IF exit_obj%=impup& ! clicked on the up button
- ADD sliderpos%,10 ! add five
- IF sliderpos%>1000
- sliderpos%=1000
- ENDIF !sliderpos%>1000
- newpos%=width%/1000*sliderpos%
- OB_X(adr%,impslide&)=newpos%
- ' Now set value in slider
- import%=sliderpos%/10
- CHAR{OB_SPEC(adr%,impslide&)}=STR$(import%)
- ' redraw the slider
- ~OBJC_DRAW(adr%,imparent&,3,x%,y%,w%,h%)
- ENDIF ! exit_obj%=impdown&
- IF exit_obj%=ok&
- hndl_ok
- ENDIF ! exit_obj%=ok&
- IF exit_obj%=cancel&
- dum%=FORM_DIAL(2,0,0,0,0,x%,y%,x%+w%,y%+h%)
- PUT x%,y%,hold$ ! restore the screen
- ' change the exit object back to non-selected
- ~OBJC_CHANGE(adr%,exit_obj%,0,x%,y%,w%,h%,0,0)
- ENDIF !exit_obj%=cancel&
- UNTIL (exit_obj%=ok& OR exit_obj%=cancel&)
- RETURN
- PROCEDURE pgm_end
- ' clean up memory, get rid of the resource and end
- ~RSRC_FREE() !toss the resource
- RESERVE FRE(0)+30000 !get the memory back
- CLOSEW #1
- EDIT !return to the editor
- RETURN
- PROCEDURE window_open
- OPENW 1
- FULLW 1
- CLEARW 1
- TITLEW #1,"STLOG Dialog Box Demo in GFA Basic"
- RETURN
- PROCEDURE hndl_ok
- dum%=FORM_DIAL(2,0,0,0,0,x%,y%,x%+w%,y%+h%)
- PUT x%,y%,hold$ ! restore the screen
- ' change the exit object back to non-selected
- ~OBJC_CHANGE(adr%,exit_obj%,0,x%,y%,w%,h%,0,0)
- ' recover the editable text fields
- nm$=CHAR{{OB_SPEC(adr%,name&)}}
- city$=CHAR{{OB_SPEC(adr%,city&)}}
- address$=CHAR{{OB_SPEC(adr%,address&)}}
- state$=CHAR{{OB_SPEC(adr%,state&)}}
- zip$=CHAR{{OB_SPEC(adr%,zip&)}}
- CLEARW 1
- PRINT AT(1,1);"Results of Dialog Box: "
- PRINT
- PRINT "Name: ";nm$
- PRINT "Address: ";address$
- PRINT "City: ";city$;" State: ";state$;" Zip: ";zip$
- ' and the radio buttons
- ' First the medical plan (3 buttons):
- select&=0 ! none selected
- FOR cnt&=1 TO 3
- IF BTST(OB_STATE(adr%,medrbtn&(cnt&)),0) ! test bit 0 (selected)
- select&=medrbtn&(cnt&)
- ENDIF ! BTST(OB_STATE(adr%,medrbtn&(cnt&)),0)
- NEXT cnt&
- IF select&<>0 ! a radio button was selected
- ' retrieve the text of the selected button
- med$=CHAR{OB_SPEC(adr%,select&)}
- PRINT "Medical Plan Selected: ";med$;" which is button ";select&-8
- ' change the radio buttons back to non-selected
- ~OBJC_CHANGE(adr%,select&,0,x%,y%,w%,h%,32,0)
- ELSE
- PRINT "No medical plan was selected!"
- ENDIF !select&<>0
- ' now the dental plan buttons
- select&=0 ! none selected
- FOR cnt&=1 TO 2 !only two dental plan buttons
- IF BTST(OB_STATE(adr%,denrbtn&(cnt&)),0) ! test bit 0 (selected)
- select&=denrbtn&(cnt&)
- ENDIF ! BTST(OB_STATE(adr%,denrbtn&(cnt&)),0)
- NEXT cnt&
- IF select&<>0 ! a radio button was selected
- ' retrieve the text of the selected button
- den$=CHAR{OB_SPEC(adr%,select&)}
- PRINT "Dental Plan Selected: ";den$;" which is button ";select&-13
- ' change the radio buttons back to non-selected
- ~OBJC_CHANGE(adr%,select&,0,x%,y%,w%,h%,32,0)
- ELSE
- PRINT "No dental plan was selected!"
- ENDIF !select&<>0
- ' get the number of dependents (read the button contents)
- nmdep$=CHAR{OB_SPEC(adr%,depnbrsl&)}
- PRINT "Number of dependents: ";nmdep$
- import$=CHAR{OB_SPEC(adr%,impslide&)}
- PRINT "Importance of plans: ";import$
- RETURN
-